import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path  from 'path'
import { baseUrl } from './src/Const';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: [{
        find: '@',
        replacement: path.resolve(__dirname, 'src')
      },
      {
        find: 'components',
        replacement: path.resolve(__dirname, 'src/components')
      }
    ],
  },
  server: {
    proxy: {
      '/api': {
        target: baseUrl,  // 把 localhost:3000 代理到 target
        secure: false,
        changeOrigin: true,
        // 若后端 api 携带了 api 前缀，就不需要重写了
        // rewrite: (path) => path.replace(/^\/api/, ''),
      }
    } 
  }
})
